package org.dromara.system.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.dromara.system.domain.Sensor;
import org.dromara.system.domain.vo.SensorVo;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * TD时序数据配置 Mapper
 *
 * @author Lion Li
 * @date 2024-10-21
 */
@Mapper
public interface SensorMapper extends BaseMapper<Sensor> {

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    void insertData(@Param("dbName") String dbName, @Param("value") float value, @Param("deviceId") Long deviceId, @Param("ts") Timestamp ts);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Float getLatestValueByDeviceId(@Param("dbName") String dbName);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    List<SensorVo> selectSensorList(@Param("dbName") String tableName);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    IPage<SensorVo> getPagedDataByDeviceId(IPage<SensorVo> page, @Param("dbName") String tableName, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Long selectCountReportData();

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Long selectTotalCount(@Param("deviceIds") Collection<Long> deviceIds);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Long getYtDataCount();

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Long getDhmDataCount();

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    Long getFiveDataCount();

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    BigDecimal getLatestData(String tableName);

    @DS("taos")
    @InterceptorIgnore(tenantLine = "true")
    void insertPointData(@Param("dbName") String dbName, @Param("value") BigDecimal value, @Param("deviceId") Long deviceId, @Param("ts") Timestamp ts);
}

